package io.renren.modules.sys.customer.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.customer.entity.BtCustomerBaseEntity;
import io.renren.modules.sys.customer.service.BtCustomerBaseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author goudandan
 * @email resjz1@163.com
 * @date 2018-09-14 17:00:01
 */
@RestController
@RequestMapping("sys/btcustomerbase")
public class BtCustomerBaseController extends AbstractController {
    @Autowired
    private BtCustomerBaseService btCustomerBaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:btcustomerbase:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = btCustomerBaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    @RequiresPermissions("sys:btcustomerbase:info")
    public R info(){
        Long uid = getUserId();
        if(uid.equals(0)){
            return R.error("非法用户！！");
        }
        BtCustomerBaseEntity btCustomerBase = btCustomerBaseService.SelectOneByUid(uid);
        if(btCustomerBase !=null){
            btCustomerBase.setUserid(0L);
            return R.ok().put("btCustomerBase", btCustomerBase);
        } else
            return R.error(-2,"没有该记录");
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:btcustomerbase:save")
    public R save(@RequestBody BtCustomerBaseEntity btCustomerBase){
        Long uid = getUserId();
        if(uid.equals(0)){
            return R.error("非法用户！！");
        }
        btCustomerBase.setUserid(uid);
        btCustomerBaseService.insertNew(btCustomerBase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:btcustomerbase:update")
    public R update(@RequestBody BtCustomerBaseEntity btCustomerBase){
        ValidatorUtils.validateEntity(btCustomerBase);
        Long uid = getUserId();
        if(uid.equals(0)){
            return R.error("非法用户！！");
        }
        btCustomerBase.setUserid(uid);
        btCustomerBaseService.updateAllColumnById(btCustomerBase);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:btcustomerbase:delete")
    public R delete(@RequestBody Long[] ids){
        btCustomerBaseService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
